package ru.urfc.portal.rest;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import ru.urfc.portal.dao.filter.Filter;
import ru.urfc.portal.dao.filter.Operator;
import ru.urfc.portal.managers.AccountingManager;
import ru.urfc.portal.model.accounting.Invoice;
import ru.urfc.portal.ui.client.Constants;

@Stateless
@Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
@Path(Constants.CLIENTS + "/{clientId}/" + Constants.INVOICES)
public class InvoiceService extends BaseService {

	@EJB AccountingManager accountingManager;
	
	@GET
	public List<Invoice> getInvoices(@PathParam("clientId") Long clientId,
			@Context HttpServletRequest request) {
		Filter filter = addFilterFromToDates(new Filter(), request);
		filter.add("name", Operator.LIKE_IGNORE_CASE, getStr(FILTER_INVOICE_NAME, request));
		return accountingManager.getInvoices(clientId, filter); 
	}
	
	@GET
	@Path("{invoiceId}")
	public Invoice getInvoice(@PathParam("clientId") Long clientId, @PathParam("invoiceId") Long invoiceId) {
		return accountingManager.getInvoice(clientId, invoiceId); 
	}

	@GET
	@Path("{invoiceId}/" + INVOICE_PRINT)
	public Invoice printInvoice(@PathParam("clientId") Long clientId, @PathParam("invoiceId") Long invoiceId) {
		return accountingManager.getInvoice(clientId, invoiceId); 
	}
	
}
